<!DOCTYPE html>
            
<HTML>
<HEAD>
<meta name="booktitle" content="Developing Applications With Objective Caml" >
 <meta charset="ISO-8859-1"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<META name="GENERATOR" content="hevea 1.05-7 of 2000-02-24">
<META NAME="Author" CONTENT="Christian.Queinnec@lip6.fr">
<LINK rel=stylesheet type="text/css" href="videoc-ocda.css">
<script language="JavaScript" src="videoc.js"><!--
//--></script>
<TITLE>
 Dependency Analysis
</TITLE>
</HEAD>
<BODY class="regularBody">
<A HREF="book-ora095.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora097.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2> Dependency Analysis</H2>
<A NAME="@concepts205"></A>
<A NAME="@fonctions342"></A>
Dependency analysis of a set of implementation and interface files
that make up an Objective CAML application pursues a double end. The first
is to get a global view of the interdependencies between modules. The
second is to use this information in order to recompile only the
absolutely necessary files after modifications of certain files.<BR>
<BR>
The <TT>ocamldep</TT> command takes a set of <TT>.ml</TT> and <TT>.mli</TT>
files and outputs the dependencies between files in <TT>Makefile</TT><A NAME="text23" HREF="book-ora102.html#note23"><SUP><FONT SIZE=2>1</FONT></SUP></A> format.<BR>
<BR>
These dependencies originate from global declarations in other
modules, either by using dot.notation (e.g. <TT>M1.f</TT>) or by
opening a module (e.g. <B>open </B> <TT>M1</TT>).<BR>
<BR>
Suppose the following files exist:<BR>
<BR>
<TT>dp.ml</TT> : 


<PRE><BR><B>let</B><CODE> </CODE>print_vect<CODE> </CODE>v<CODE> </CODE><CODE>=</CODE><CODE> </CODE><BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><B>for</B><CODE> </CODE>i<CODE> </CODE><CODE>=</CODE><CODE> </CODE><CODE>0</CODE><CODE> </CODE><B>to</B><CODE> </CODE>Array.length<CODE> </CODE>v<CODE> </CODE><B>do</B><CODE> </CODE><BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>Printf.printf<CODE> </CODE><CODE>"%f "</CODE><CODE> </CODE>v<CODE>.</CODE><TT>(</TT>i<TT>)</TT><BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE><B>done</B>;<BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>print_newline();;<BR>

</PRE>
<BR>
<BR>
and <TT>d1.ml</TT> : 


<PRE><BR><B>let</B><CODE> </CODE>init<CODE> </CODE>n<CODE> </CODE>e<CODE> </CODE><CODE>=</CODE><CODE> </CODE><BR><CODE> </CODE><CODE> </CODE><B>let</B><CODE> </CODE>v<CODE> </CODE><CODE>=</CODE><CODE> </CODE>Array.create<CODE> </CODE><CODE>4</CODE><CODE> </CODE><CODE>3</CODE><CODE>.</CODE><CODE>1</CODE><CODE>4</CODE><CODE> </CODE><B>in</B><CODE> </CODE><BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>Dp.print_vect<CODE> </CODE>v;<BR><CODE> </CODE><CODE> </CODE><CODE> </CODE><CODE> </CODE>v;;<BR>

</PRE>
<BR>
<BR>
Given the name of these files, the <TT>ocamldep</TT> command will output
the following dependencies: 
<PRE>
$ ocamldep dp.ml d1.ml array.ml array.mli printf.ml printf.mli
dp.cmo: array.cmi printf.cmi 
dp.cmx: array.cmx printf.cmx 
d1.cmo: array.cmi dp.cmo 
d1.cmx: array.cmx dp.cmx 
array.cmo: array.cmi 
array.cmx: array.cmi 
printf.cmo: printf.cmi 
printf.cmx: printf.cmi 
</PRE> The dependencies are determined for both the bytecode and the native
compiler. The output is to be read in the following manner:
production of the file <TT>dp.cmo</TT> depends on the files
<TT>array.cmi</TT> and <TT>printf.cmi</TT>. Files with the extension
<TT>.cmi</TT> depend on files with the same name and extension
<TT>.mli</TT>. And the same holds by analogy for <TT>.ml</TT> files with
<TT>.cmo</TT> and <TT>.cmx</TT> files.<BR>
<BR>
The object files of the distribution do not show up in the dependency
lists. In fact, if <TT>ocamldep</TT> does not find the files
<TT>array.ml</TT> and <TT>printf.ml</TT> in the current directory, it
will find them in the library directory of the installation and
produce the following output:
<PRE>
$ ocamldep dp.ml d1.ml
d1.cmo: dp.cmo 
d1.cmx: dp.cmx 
</PRE>To give new file search paths to the <TT>ocamldep</TT> command, the
<TT>-I directory</TT> option is used, which adds a directory to the list of
include directories.<BR>
<BR>
<HR>
<A HREF="book-ora095.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora097.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
